package org.csu.corp.service;

import org.csu.corp.entity.RespPageBean;
import org.csu.corp.entity.Sign;
import org.csu.corp.persistence.SignMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SignService {

    @Autowired
    private SignMapper signMapper;

    public Integer sign(Sign sign) {
        return signMapper.insert(sign);
    }

    public RespPageBean getSignByPage(Integer page, Integer size, String workId) {
        if (page != null && size != null) {
            page = (page - 1) * size;
        }
        List<Sign> data = null;
        if (workId == null || workId.equals("")) data = signMapper.getSignByPage(page, size);
        else data = signMapper.getEmployeeByPageWithWorkId(page, size, workId);

        Long total = signMapper.getTotal(null);
        RespPageBean bean = new RespPageBean();
        bean.setData(data);
        bean.setTotal(total);
        return bean;
    }

    public Integer deleteSignById(Integer id) {
        return signMapper.deleteByPrimaryKey(id);
    }

    public Integer updateSign(Sign sign) {
        if (sign.getId() == null) return 0;
        return signMapper.updateByPrimaryKey(sign);
    }
}
